Skip to content

Conversation

@darshan2456
Copy link

@darshan2456 darshan2456 commented Jan 15, 2026

This PR documents the existing convention for representing complex numbers
using scalar floating-point format characters in the struct module.

Specifically, it clarifies that complex numbers may be represented as two
consecutive floating-point values (real part followed by imaginary part),
with the f and d format characters determining the component type.

The clarification is applied consistently to both the runtime docstring
and the library documentation.


📚 Documentation preview 📚: https://cpython-previews--143879.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Jan 15, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 15, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@darshan2456
Copy link
Author

This is a documentation-only change; no NEWS entry is needed. Could a triager please add the skip news label?

@skirpichev skirpichev self-requested a review January 15, 2026 19:30
Comment on lines +283 to +286
Complex numbers may also be represented using two consecutive floating-point
format characters. In this case, the real part is stored first, followed by
the imaginary part. The format characters ``f`` and ``d`` determine the type
used for each component.
Copy link
Member

@skirpichev skirpichev Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The are note (10) right below. Much more precise and clear, IMO. What means "may also be"?

Are you used LLM to generate PR? It looks you haven't read the documentation by yourself. Please see this:

Maintainers may close issues and PRs that are not useful or productive, including those that are fully generated by AI. If a contributor repeatedly opens unproductive issues or PRs, they may be blocked.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have read the documentation myself and have composed it myself only. how about this then?
"Complex numbers are represented (by convention), using two consecutive floating-point format characters. In this case, real part is stored first, and then the imaginary part. the format characters f and d determine the type used for each component"

is this okay?

@@ -2696,7 +2688,9 @@ these can be preceded by a decimal repeat count:\n\
x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;\n\
?: _Bool (requires C99; if not available, char is used instead)\n\
h:short; H:unsigned short; i:int; I:unsigned int;\n\
l:long; L:unsigned long; f:float; d:double; e:half-float.\n\
l:long; L:unsigned long; f:float; d:double; e:half-float.\n\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change is unrelated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah my bad, it is just whitespace error on my side

Comment on lines +2692 to +2693
For complex numbers, the real and imaginary parts are represented by two\n\
consecutive values of the specified floating-point type.\n\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading. No one "specified" a "floating-point type". 'F' and 'D' formats specify a complex C types.

BTW, there are already opened PR (#143675). Next time please check the issue thread and comment why you would like to open an extra PR.

I think it's better to close this. But CC @vstinner

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah my bad. this is my first PR and i am still getting accustomed to contributing to open source. i missed checking for an existing PR on the issue. ill make sure to do that in the future. thanks for the review. i am closing this PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants